/**
 * Application Application.java
 */

package CCT220_Aula17_Exercicio01_13106;


import java.util.Random;

import javax.swing.JOptionPane;


/**
 * </br>******************************
 * </br>Project: CCT220
 * </br>Package: CCT220_Aula17_Exercicio01_13106
 * </br>Class: Application
 * </br>Last Change: 26/10/2011 20:38:45 by marcel
 * </br>Description:
 * </br>******************************</br>
 * 
 * @author marcel
 * @author 13106
 * 
 */
public class Application {

	public static void main(String[] args) {

		Random r = new Random();
		int opUser = 0;
		int userVal = -1;
		int pcVal = r.nextInt(100);

		Object[] options = { "PAR", "IMPAR" };
		opUser = JOptionPane.showOptionDialog(null, "Par ou Ímpar?",
		        "Jogo do para ou ímpar", JOptionPane.DEFAULT_OPTION,
		        JOptionPane.QUESTION_MESSAGE, null, options, null);

		do {

			try {
				userVal = Integer.parseInt(JOptionPane
				        .showInputDialog("Entre com seu valor(0-99):"));
			} catch (NumberFormatException e) {
				JOptionPane.showMessageDialog(null,
				        "Entre com valores numericos", "Erro",
				        JOptionPane.ERROR_MESSAGE);
			}
			if (userVal < 0 || userVal > 99) {
				JOptionPane.showMessageDialog(null,
				        "Entre cm valores entre 0 e 99", "Erro",
				        JOptionPane.ERROR_MESSAGE);
			}
		} while (userVal >= 0 && userVal < 100);
		if ((userVal + pcVal) % 2 == opUser) {
			JOptionPane.showMessageDialog(null, "Voce ganhou", "Vitoria",
			        JOptionPane.INFORMATION_MESSAGE);
		} else {
			JOptionPane.showMessageDialog(null, "Voce perdeu", "Derrota",
			        JOptionPane.ERROR_MESSAGE);
		}
	}

}
